/**
 * 
 */
package com.htht.tourism.action;

import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.htht.tourism.domain.Response;
import com.htht.tourism.domain.link.HotelParam;
import com.htht.tourism.domain.link.HouseParam;
import com.htht.tourism.intf.HouseService;
import com.htht.tourism.utils.ValidatorResultHandler;

/**
 * @author wuqiwei
 *
 */
@Controller
@ResponseBody
@RequestMapping("/house")
public class HouseController {
	@Resource
	private HouseService housrServise;
	
	/**
	 * 查询海景房信息
	 * @author:wuqiwei
	 * @param @param param
	 * @param @param result
	 * @param @return
	 * @date:2017年3月14日下午3:46:16
	 */
	@RequestMapping(value = "/getAll", method = RequestMethod.POST)
	public Response queryAllUser(@RequestBody @Validated HouseParam param,
			BindingResult result,HttpServletResponse response ) {
		Response retVal = ValidatorResultHandler.handle(result);
		if (retVal == null) {
			Map map = this.housrServise.getAll(param);
			if (map.size() > 0) {
				return Response.getInstance().success(map);
			} else {
				return Response.getInstance().failure("查询失败！");
			}
		} else {
			return retVal;
		}
	}
	/**
	 * 修改海景房信息
	 * @author:wuqiwei
	 * @param @param param
	 * @param @param result
	 * @param @return
	 * @date:2017年3月15日下午2:57:18
	 */
	@RequestMapping(value = "/update", method = RequestMethod.POST)
	public Response update(@RequestBody @Validated HouseParam param,
			BindingResult result) {
		Response retVal = ValidatorResultHandler.handle(result);
		if (retVal == null) {
			int a = this.housrServise.update(param);
			if (a > 0) {
				return Response.getInstance().success(a);
			} else {
				return Response.getInstance().failure("修改失败！");
			}
		} else {
			return retVal;
		}
	}
	/**
	 * 添加海景房信息
	 * @author:wuqiwei
	 * @param @param param
	 * @param @param result
	 * @param @return
	 * @date:2017年3月15日下午3:06:52
	 */
	@RequestMapping(value = "/add", method = RequestMethod.POST)
	public Response add(@RequestBody @Validated HouseParam param,
			BindingResult result) {
		Response retVal = ValidatorResultHandler.handle(result);
		if (retVal == null) {
			int a = this.housrServise.add(param);
			if (a > 0) {
				return Response.getInstance().success(a);
			} else {
				return Response.getInstance().failure("添加失败！");
			}
		} else {
			return retVal;
		}
	}
	/**
	 * 删除海景房信息
	 * @author:wuqiwei
	 * @param @param param
	 * @param @param result
	 * @param @return
	 * @date:2017年3月16日上午9:22:45
	 */
	@RequestMapping(value = "/del", method = RequestMethod.POST)
	public Response del(@RequestBody @Validated HouseParam param,
			BindingResult result) {
		Response retVal = ValidatorResultHandler.handle(result);
		if (retVal == null) {
			int a = this.housrServise.del(param);
			if (a > 0) {
				return Response.getInstance().success(a);
			} else {
				return Response.getInstance().failure("删除失败！");
			}
		} else {
			return retVal;
		}
	}
}
